/*
 * @features: 观察属性
 * @description: 说明
 * @Date: 2021-10-02 13:58:09
 * @Author: judu233(769471424@qq.com)
 * @LastEditTime: 2021-10-10 17:41:07
 * @LastEditors: judu233
 */

import c3d from "../../../cc";
const { ccclass, property, executeInEditMode, disallowMultiple, menu } = c3d._decorator;

/**自动检查识别的数组,你可以准备自己的组件放上去自动识别 ,系统组件只能是实例，自定义的可以是字符串*/
const COMP_MAP_ARR: Map<string, [any, string]> = new Map<string, [any, string]>([
    [`Label`, [c3d.Label, `string`]],
    [`RichText`, [c3d.RichText, `string`]],
    [`EditBox`, [c3d.EditBox, `string`]],
    [`Slider`, [c3d.Slider, `progress`]],
    [`ProgressBar`, [c3d.ProgressBar, `progress`]],
    [`Toggle`, [c3d.Toggle, `isChecked`]],
    [`VmSprite`, [`VmSprite`, `index`]],
    [`VmPage`, [`VmPage`, `index`]],
]);


@ccclass(`VmWatch`)
export default class VmWatch {
    /**组件名 */
    @property({ displayName: `组件名`, tooltip: `绑定组件的名字` })
    componentName: string = "";

    /**组件属性 */
    @property({ displayName: `组件属性`, tooltip: `组件上需要监听的属性` })
    componentProperty: string = "";

    /**双向监听 */
    @property({ displayName: `双向监听`, tooltip: `激活controller,以开启双向绑定，否则只能接收消息` })
    controller: boolean = false;

    /**多路径模式 */
    @property({ displayName: `多路径`, tooltip: `是否启用模板多路径模式` })
    useMultipathMode: boolean = false;

    /**监听路径 */
    @property({ displayName: `路径`, visible(this: VmWatch) { return !this.useMultipathMode; } })
    path: string = ``;

    /**监听路径 */
    @property({ displayName: `路径`, type: [c3d.CCString], visible(this: VmWatch) { return this.useMultipathMode; } })
    pathArr: string[] = [];

    /**是否能监听组件的数据 */
    _canWatchComponent: boolean = false;

    /**监听的组件对象 */
    _watchComponent: c3d.Component = null;

    /**储存模板多路径的值 */
    templateValueArr: any[] = [];

    /**监听数据对象 */
    _canWatchData = false;

    /**双向绑定是否开启深度遍历，否则只会遍历1层 */
    _controllerIsWatchDeep = false;

}